<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>任务列表</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <style>
        .aui-bar-nav {
            background-color: #FFF;
            color: #000;
            position: fixed;
        }

        .aui-bar-nav .aui-iconfont {
            color: #000!important;
            font-weight: bold;
        }

        .aui-content {
            margin-top: 2.25rem;
        }

        .tishi {
            font-size: 0.7rem;
            text-align: center;
            color: #999;
            padding-bottom: 1rem;
        }
    </style>
</head>

<body>
    <header id="header" class="aui-bar aui-bar-nav">
        <a class="aui-pull-left aui-btn" tapmode onclick="comeBack()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">试玩任务</div>
    </header>
    <div id="aui-content" class="aui-content task income-details">
        <div class="task-top"><span>1.下载应用</span> <span>2.打开试玩</span><span>3.领取现金</span></div>
        <div class="task-tit">标准任务</div>
        <div class="cent-box">
            <div class="wrap">
            </div>
        </div>
        <div class="tishi">下拉加载更多 </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../script/md5.min.js"></script>
<script type="text/javascript">
    var pageNum = 1,
        whterScroll = true;
    apiready = function() {
        initHeard();
        $api.fixStatusBar($api.byId('aui-content'));
        _downRefresh(function() {
            pageNum = 1;
            whterScroll = true;
            getPageInit()
            api.refreshHeaderLoadDone();
        });
        scrollBottom();
        api.addEventListener({
            name: 'viewappear'
        }, function(ret, err) {
            pageNum = 1;
            whterScroll = true;
            getPageInit()
        });
    };
    //上拉加载更多
    function scrollBottom() {
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 60 //设置距离底部多少距离时触发，默认值为0，数字类型
            }
        }, function(ret, err) {
            if (whterScroll) { //1开启执行 0停止执行   防止连续滚动，等加载数据之后在进行滚动。
                pageNum += 1;
                whterScroll = !whterScroll;
                getPageInit();
            }
        });
    };
    //初次进入首页数据
    function getPageInit() {
        _loading();
        _ajax("index/allTask", {
            p: pageNum
        }, function(res, err) {
            console.log(JSON.stringify(res));
            
            if (res) {
                if (res.errCode == 1) {
                      
                    if (res.data.data.length > 0) {
                        $api.css($api.dom(".cent-box"), 'display: block ;');
                        var info = res.data.data,
                            leng = info.length,
                            html = '';
                        for (var i = 0; i < leng; i++) {
                            html += '<div class="item" tapmode onclick="openWin(' + "'trial_detail'" + ',{tid:' + info[i].id + '},false)">';
                            html += '<div class="left"><img src="' + imgurl + info[i].img + '"></div>';
                            html += '<div class="cent">';
                            html += '<div>' + info[i].title + '</div>';
                            html += '<p>' + info[i].more + '</p></div>';
                            html += '<div class="right">+' + info[i].task_money + '</div></div>';
                        }
                        if (pageNum == 1) {
                            $(".cent-box .wrap").html(html);
                        } else {
                            $(".cent-box .wrap").append(html);
                        }
                        whterScroll = true;
                        $(".tishi").html("下拉加载更多")
                    } else {
                      
                        // $api.css($api.dom(".cent-box"), 'display: none ;');
                        whterScroll = false;
                        $(".tishi").html("没有更多了")
                    }
                } else if (res.errCode == -1) {
                    openWin('login');
                }
            } else {
                console.log(JSON.stringify(res));
                
                _msg("网络错误");
            }
            _loadingCloes();
        })
    }
</script>

</html>
